# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

inherit webapp eutils

DESCRIPTION="A lightweight 'Google Hack' Honeypot. GHH is modular and easily extended,
written in PHP."
HOMEPAGE="http://ghh.sourceforge.net/"
IUSE="doc"
GHH_SITE="mirror://sourceforge/${PN}/GHH-"
GHH_POTS="${GHH_SITE}Custom_Template.zip
		${GHH_SITE}Haxplorer.zip
		${GHH_SITE}PHPBB_Install.zip
		${GHH_SITE}PHPFM.zip
		${GHH_SITE}PHP_Ping.zip
		${GHH_SITE}PHP_Shell.zip
		${GHH_SITE}PhpSysInfo.zip
		${GHH_SITE}SquirrelMail.zip"
SRC_URI="${GHH_POTS}
		doc? ( mirror://sourceforge/${PN}/UserManualv1.0.pdf )"
LICENSE="GPL-2"
KEYWORDS="~x86"
DEPEND="virtual/php"

src_unpack() {
	for pots in ${GHH_POTS/${GHH_SITE}}; do
		mkdir ${pots/.zip}
		unzip ${pots} -d${pots/.zip}
	done
}
src_compile() {
	echo "Nothing to compile."
}

src_install() {

	webapp_src_preinst

	# handle documentation files
	#
	# NOTE that doc files go into /usr/share/doc as normal; they do NOT
	# get installed per vhost!

	einfo "Installing docs"
	cd ${WORKDIR}/${P}
	dodoc ${docs}
	for doc in ${docs}; do
		rm -f ${doc}
	done

	einfo "Copying main files" 
	cp -R * ${D}${MY_HTDOCSDIR}

	# we install the .htaccess file to enable support for clean URLs
	cp .htaccess ${D}${MY_HTDOCSDIR}

	# create the files upload directory
	mkdir ${D}${MY_HTDOCSDIR}/files
	webapp_serverowned ${MY_HTDOCSDIR}/files

	# Identify any script files that need #! headers adding to run under
	# a CGI script (such as PHP/CGI)
	#
	# for drupal, we *assume* that all .php files need to have CGI/BIN
	# support added
	for x in `find . -name '*.php' -print ` ; do
		webapp_runbycgibin php ${MY_HTDOCSDIR}/$x
	done

	#All files must be owned by server
	for x in `find . -type f -print` ; do
		webapp_serverowned ${MY_HTDOCSDIR}/$x
	done

	webapp_configfile ${MY_HTDOCSDIR}/sites/default/settings.php
	webapp_postinst_txt en ${FILESDIR}/postinstall-en.txt
	webapp_src_install

	if use cleanup; then
		ewarn "'cleanup' in USE, so cleaning DISTFILES."
		for del in ${DRUPAL_MODS} ${DRUPAL_THEMES}; do
			rm ${DISTDIR}/${del/${DRUPAL_SITE}}
		done
		rm ${FILESDIR}/digest-${P}
	else	
		einfo "No 'cleanup' in USE, so leaving DISTFILES as is."
	fi
}

